// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        enemybar: {
            type: cc.Node,
            default: null,
        },

        //添加文字label
        hplabel: {
            type: cc.Label,
            default: null,
        },

        propprefab: {
            default: null,
            type: cc.Prefab,
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.tinyhp = 100;
        this.score = 0;
    },

    start() {

    },

    onBeginContact: function (contact, selfCollider, otherCollider) {
        if (otherCollider.node.name == 'bullet') {
            this.jianxuey(); 
            otherCollider.node.destroy();
        }
    },

    jianxuey() {
        var pp = this.enemybar.getComponent(cc.ProgressBar);//取得进度跳控件
        pp.totalLength = pp.totalLength - 10;//改变进度条（即血条）
        this.tinyhp = this.tinyhp - 10;//改变雪值（即string）
        this.hplabel.string = this.tinyhp;//当前HP=文字string
        if (pp.totalLength <= 0) {
            this.prentNode.newStar(this.node.position);//把飞机死亡的位置传进去
            this.node.destroy()//删除飞机
        }
    },

    update(dt) {
        if (this.node.y <= -700) {
            this.node.destroy();
        }
    },
});
